package com.yl.rabbitmq.day03;

import com.rabbitmq.client.Channel;
import com.yl.rabbitmq.utils.RabbitMQUtil;

import java.util.Scanner;

/**
 * @author yangl
 * 消息在手动应答时不丢失，放回队列中重新消费
 */
public class Producer03 {
    //队列名称
    public static final String TASK_QUEUE_NAME = "ack_name";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMQUtil.getChannel();
        //声明队列
        channel.queueDeclare(TASK_QUEUE_NAME,false, false, false,null);
        //从控制台输入
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            channel.basicPublish("", TASK_QUEUE_NAME,null, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息：" + message);
        }
    }
}
